import time
import os
import webbrowser
import threading
import tkinter as tk


def stop():
    global flag
    flag = False


def start():
    global ischeck
    url = brush_url.get()
    num1 = int(browser_num.get())
    num2 = int(web_num.get())
    time2 = float(time1.get())

    for j in range(num1):
        for i in range(num2):
            if flag:
                webbrowser.open(url, new=0, autoraise=True)
                time.sleep(time2)
        os.system('taskkill /F /IM msedge.exe')


def on_start():
    thread1 = threading.Thread(target=start)
    thread1.start()


# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
    global flag
    flag = True
    layout1 = tk.Tk()
    layout1.title('刷网页浏览量（1.0版）')
    layout1.geometry('520x260')
    layout1.resizable(False, False)

    tk.Label(layout1, text='请输入网址：', font=24).grid(row=1, column=0)
    brush_url = tk.Entry(layout1, width=30, bd=2)
    brush_url.grid(row=1, column=1, pady=10)

    tk.Label(layout1, text='请输入打开多少次浏览器：', font=15).grid(row=2, column=0)
    browser_num = tk.Entry(layout1, width=20, bd=2)
    browser_num.grid(row=2, column=1, pady=10)

    tk.Label(layout1, text='请打开多少次网页：', font=15).grid(row=3, column=0)
    web_num = tk.Entry(layout1, width=20, bd=2)
    web_num.grid(row=3, column=1, pady=10)

    tk.Label(layout1, text='打开网页间隔时间', font=15).grid(row=4, column=0)
    time1 = tk.Entry(layout1, width=20, bd=2)
    time1.grid(row=4, column=1, pady=10)

    stop_btn = tk.Button(layout1, text='停止', command=stop)
    stop_btn.grid(row=5, column=0, pady=10)

    stop_btn = tk.Button(layout1, text='开始', command=on_start)
    stop_btn.grid(row=5, column=1, pady=10)
    layout1.attributes('-topmost', 'true')

    layout1.mainloop()
